package com.hiultra.archive.controller;

import com.hiultra.archive.domain.ArcAlarm;
import com.hiultra.archive.service.IArcAlarmService;
import com.hiultra.archive.utils.sgsm.SM2Util;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.page.TableDataInfo;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报警Controller
 *
 * @author ls
 * @date 2022-07-28
 */
@Api(tags = "报警Controller")
@RestController
@RequestMapping("/environment/alarm")
public class ArcAlarmController extends BaseController {
    @Autowired
    private IArcAlarmService arcAlarmService;
    @Value("${pubKey}")
    private String pubKey;
    @Value("${priKey}")
    private String priKey;

    /**
     * 查询报警列表
     */
    @ApiOperation(value = "查询报警列表", notes = "查询报警列表")
    @PreAuthorize("@ss.hasPermi('environment:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArcAlarm arcAlarm) {
        startPage();
        List<ArcAlarm> list = arcAlarmService.selectArcAlarmList(arcAlarm);

//        String pubKey = "042efc8b5f691580e3fa384bbe94f7cae92d3ea916d5db005b3f51ea8b622b75a17136ac65de1a7be516b17793c900a4ef95724b05c7e48cf9e41f4a140a87ee10";
//        String priKey = "6c44b77e9e17e21c13afa1bb33afde166a229a53d34158d2e64ddb8fd4444ff5";
//
//        String a = new SM2Util().encryptBySM2("你真是个", pubKey);
//        System.out.println(a);
//        String deStr = new SM2Util().decryptBySM2(a, priKey);
//        System.out.println(deStr);

        return getDataTable(list);
    }

    public static void main(String[] args) {
        String pubKey = "04ac253373f255a68ba0f9fe09e365fadd6c19e9c15b18497aaa6aa11e1097be16e94a648a20e4a60ab60d5c2a1c4f03a1e6d65ddd376cfdab895a4b1d444558dc";
//        String priKey = "6c44b77e9e17e21c13afa1bb33afde166a229a53d34158d2e64ddb8fd4444ff5";
        String priKey = "fba2f90024550bce4b243f5980ffe3d8dfe41897f32deec5b875c188a6715f00";

        //私钥解密  公钥加密
        //  String a = new SM2Util().encryptBySM2("你真是个", pubKey);
        String a = "044b3f26e09e51708e7a0f66442943e1dc7056b022689923ff6694ced17e16e41a37884db0e73c32522fd4e28026dd65b26b1bc4d8ed8523420a14cf1c53cfc6575eeb15474a9b5b1d317f58d2cd93eb9a39eabb5056976cc15713b5d8c1e334fcd6ba0ee8f086c92bc8c3d715b31f564708eb7d232cac1fa15eabb94d5043e5adc85a82829d636fdbc5733a9a42cdb84f75a09b18e604e31d920e52c924cd793732c456df1047086cc04024540fa7627f3292f1f4ea84e73c8e50c0987f974e40e96df2e541a5c17f4f9b35833b0d68fa2a924b86e0684758f028acf02ede966c8f9bca381f2f4afe57527d0c054f3cbc937ae0f4b35d497a4e33b6fe7354545b26429400ec072e0d198192f6e16b4a985d476148cad2c92f82223b6cad581bf7228be582015a05c476d93fd2092060967cc8d03b6be17f1cb8d97c9af1ce14cc540ec7ed462eef41776133165327277c389585b0bdcacaebb8590ff9a32f25de275eac16d8f63d82e4d5b0d94e0dcba5fcb2a14e7b472e41150fd167efa33a5d917dbd3b1814403f58710c052a11b172cf5233b7d378ac85fa1a653a6e0e3c586407b49a6b59934bfb517fd3eed4231a3c1a0c48d8ead44cd285f5a54fd52c3daf74a5703113a88256e59eba33852a0a6076cdd3cb39f838c50d09f7b90ff70cf31571c8d9143a0e56b887c07ac1cf74378d8802b2d6c2133a17b1c42419f740e2babc3c4c57861f0a10ea899e1db6fc53d14323567fa5233a1805f69ec7a6195fbcdc0d8067aa5c0e0205096f91885f17eddd603fc18269716ee5b4c7737fd53a6938e2a276cb751414111466755413e65053924eb237633332f44a56afb72e218feb8da7ce9d3d2de1ebfb370dcb36fe20e967d1c1be255303aa4c9e928ce0afdc25b5db5ce4ef010a3428f9bfc58db36d4b35282890f01f85d164b09cb25d9d54411cba7da3b1067e9b71fdd90949947e6420102fe257d94557909c82e6014affeda264a48e2e8a68fd2f09adf6964f5423d7622f6b22388bc049d90e7295ff0f1387f6db78035f990a02aa8bd82617dee6138c47dc84c7f3db472d86e591ade12741fc60798d828193215dde87d117e00aac3ac0e0698f63499084c717805b4f815e1a18ba8403eb115114aa1b98d4dd569b57e990910f9691f73f6d07ebaab5f0e118b0e9740f0e1ff4efa28b4b5d8d9d7a1d3b0cbfcb47328fae1d6970137c38138b10eb10bc6bbd59cf70b5d8c8dbf0392a5f8e4db98cedcc8f7a9abd4290128aa71d58f7963d871c7fc7415da74e33b5bbeb8a149211e39361d6e0bd6b1ee23e7cac354fcfc491b97c68fddfd2bf75ab4ebdcc754b298e2480c6386ca9dc2f2d9007f566982471a04cfa0def427139b14a7d1fb44a8d90bcdfa5e201bad620713bbc1ffbdcf047d96f575ac3ebd0d59f61479d1f3e6aa0642d57aa999f4c62f2961fd982f394d76a765b44d92bb035942e9cdf2e933f6d143e7a74b0b637e1a2d0";

        //System.out.println(a);
        String deStr = new SM2Util().decryptBySM2(a, priKey);
        System.out.println(deStr);
    }

    /**
     * 导出报警列表
     */
    @ApiOperation(value = "导出报警列表", notes = "导出报警列表")
    @PreAuthorize("@ss.hasPermi('environment:alarm:export')")
    @Log(title = "报警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcAlarm arcAlarm) {
        List<ArcAlarm> list = arcAlarmService.selectArcAlarmList(arcAlarm);
        ExcelUtil<ArcAlarm> util = new ExcelUtil<ArcAlarm>(ArcAlarm.class);
        util.exportExcel(response, list, "报警数据");
    }

    /**
     * 获取报警详细信息
     */
    @ApiOperation(value = "获取报警详细信息", notes = "获取报警详细信息")
    @PreAuthorize("@ss.hasPermi('environment:alarm:query')")
    @GetMapping(value = "/{alarmId}")
    public AjaxResult getInfo(@PathVariable("alarmId") Long alarmId) {
        return AjaxResult.success(arcAlarmService.selectArcAlarmByAlarmId(alarmId));
    }

    /**
     * 新增报警
     */
    @ApiOperation(value = "新增报警", notes = "新增报警")
    @PreAuthorize("@ss.hasPermi('environment:alarm:add')")
    @Log(title = "报警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcAlarm arcAlarm) {
        return toAjax(arcAlarmService.insertArcAlarm(arcAlarm));
    }

    /**
     * 修改报警
     */
    @ApiOperation(value = "修改报警", notes = "修改报警")
    @PreAuthorize("@ss.hasPermi('environment:alarm:edit')")
    @Log(title = "报警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcAlarm arcAlarm) {
        return toAjax(arcAlarmService.updateArcAlarm(arcAlarm));
    }

    /**
     * 删除报警
     */
    @ApiOperation(value = "删除报警", notes = "删除报警")
    @PreAuthorize("@ss.hasPermi('environment:alarm:remove')")
    @Log(title = "报警", businessType = BusinessType.DELETE)
    @DeleteMapping("/{alarmIds}")
    public AjaxResult remove(@PathVariable Long[] alarmIds) {
        return toAjax(arcAlarmService.deleteArcAlarmByAlarmIds(alarmIds));
    }
}
